﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace SoufunData
{
    public partial class ImportExcelData : DevExpress.XtraEditors.XtraForm
    {
        public ImportExcelData()
        {
            InitializeComponent();
        }

        public string labelTitle;
        private int _importType;

        private void ImportExcelData_Load(object sender, EventArgs e)
        {
            labelControl1.Text = this.labelTitle;
            switch (labelTitle)
            {
                case "土地供应":
                    _importType = 0;
                    break;
                case "土地成交":
                    _importType = 1;
                    break;
            }
            
            
        }

        private void btn_excelPath_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            openFileDialog1.Filter = "Excel文件|*.xls;*.xlsx";
            openFileDialog1.FileName = "";
            openFileDialog1.ShowDialog();
            string fileName = openFileDialog1.FileName;
            btn_excelPath.Text = fileName;

            gridControl1.DataSource = null;
            gridView1.Columns.Clear();
            gridView1.GroupPanelText = "请选择Excel文件";
            if (fileName == "")
            {
                return;
            }
            DataSet ds = Common.LoadDataFromExcel(fileName);
            if (ds == null || ds.Tables.Count == 0
                || ds.Tables[0].Columns.Count < 4)
            {
                XtraMessageBox.Show("选择的Excel文件数据格式有问题,请核对！");
                btn_excelPath.Text = "";
                return;
            }
            gridControl1.DataSource = ds.Tables[0];
            gridView1.GroupPanelText = "共有" + ds.Tables[0].Rows.Count + "条数据";
        }
    }
}